#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:do_dict_input.py
# author:肖宇轩
# datetime:2024-11-12 19:40
# software: VsCode

"""
有一个字典数组，存放了一个小组N个同学的信息；
A  请从键盘输入数据，初始化这N个同学的信息；
B  按照年龄从大到小的顺序，输出这N个同学的信息；
"""


students = []

n = int(input("请输入同学的数量: "))

for i in range(n):
    print(f"\n请输入第 {i + 1} 个同学的信息:")
    name = input("姓名: ")
    city = input("城市: ")
    age = int(input("年龄: "))  

    student_info = {
        "name": name,
        "city": city,
        "age": age
    }

    students.append(student_info)

students_sorted = sorted(students, key=lambda x: x["age"], reverse=True)

print("\n按照年龄从大到小的顺序输出同学信息:")
for student in students_sorted:
    print(f"姓名: {student['name']}, 城市: {student['city']}, 年龄: {student['age']}")
